home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / Anwendun / 7UP_PD / DEADKEY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-17  |  9.1 KB  |  377 lines

  1. /* Deadkeys */
  2. /*****************************************************************************
  3. *
  4. *                                              7UP
  5. *                                        Modul: DEADKEY.C
  6. *                                     (c) by TheoSoft '92
  7. *
  8. *****************************************************************************/
  9. #include <portab.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <aes.h>
  14.  
  15. #include "7up.h"
  16. #include "alert.h"
  17. #include "di_fly.h"
  18.  
  19. extern OBJECT *winmenu, *menueditor;
  20. char *split_fname(char *pathname);
  21. char *find_7upinf(char *path, char *ext, int read_write);
  22. char shortcutfile[32]="";
  23. int scaktiv;
  24.  
  25. #if GEMDOS
  26. #include <ext.h>
  27.  
  28. typedef struct /* Deadkeystruktur */
  29. {
  30.     unsigned char dead,sym,sign;
  31. } DK;
  32.  
  33. static DK dk[]= /* Deadkeyliste  */
  34. {
  35.     '\'','a','á',
  36.     '\'','e','é',
  37.     '\'','E','É',
  38.     '\'','i','í',
  39.     '\'','o','ó',
  40.     '\'','u','ú',
  41.  
  42.     '`','a','à',
  43.     '`','A','À',
  44.     '`','e','è',
  45.     '`','i','ì',
  46.     '`','o','ò',
  47.     '`','u','ù',
  48.  
  49.     '^','a','â',
  50.     '^','e','ê',
  51.     '^','i','î',
  52.     '^','o','ô',
  53.     '^','u','û',
  54.  
  55.     '~','a','ã',
  56.     '~','A','Ã',
  57.     '~','n','ñ',
  58.     '~','N','Ñ',
  59.     '~','o','õ',
  60.     '~','O','Õ',
  61.  
  62.     'o','a','å',
  63.     'o','A','Å',
  64.  
  65.     '/','o','ø',
  66.     '/','O','Ø',
  67.  
  68.     ',','c','ç',
  69.     ',','C','Ç',
  70.  
  71.     '_','a','ª',
  72.     '_','o','º',
  73.  
  74.     '\"','e','ë',
  75.     '\"','i','ï',
  76.     '\"','y','ÿ',
  77.  
  78.     'a','e','æ',
  79.     'A','E','Æ',
  80.     '<','<','«',
  81.     '>','>','»',
  82.     '!','!','¡',
  83.     '?','?','¿',
  84.     'f','f',' ',
  85.     'F','F',' ',
  86.  
  87.     '1','2','½',
  88.     '1','4','¼',
  89.  
  90.     '+','-','±',
  91.     '>','=','≥',
  92.     '<','=','≤',
  93.  
  94.     '^','2','²',
  95.     '^','3','³'
  96. };
  97.  
  98. static char *shortcut=NULL;
  99.  
  100. int deadkey(int dead, int key, char **cp)                /* Zeichen wandeln              */
  101. {
  102.     register int i;
  103.     register char sct[4];
  104.     
  105.     sct[0]=dead;
  106.     sct[1]=key;
  107.     sct[2]='=';
  108.     sct[3]=0;
  109.     *cp=NULL;    
  110.     if(shortcut && (*cp=strstr(shortcut,sct))!=NULL)/* Shortcut aus Datei */
  111.     {                                                                /* nachträglich erweitert */
  112.         (*cp)+=3;
  113.         return(0);
  114.     }
  115.     
  116.     for(i=0; i<sizeof(dk)/3; i++)
  117.     {
  118.         if(dk[i].dead == dead)                  /* Deadkey gefunden             */
  119.             for(i; dk[i].dead == dead; i++)  /* weiter mit den Symbolen    */
  120.                 if(dk[i].sym == key)             /* Zeichen gefunden             */
  121.                     return(dk[i].sign);          /* Sonderzeichen zurückgeben */
  122.     }
  123.     return(key);
  124. }
  125.  
  126. int isdeadkey(int dead)              /* gehört das Zeichen zu den Deadkeys */
  127. {
  128.     register int i;
  129.     register char *cp;
  130.     
  131.     if(shortcut)                         /* nachladbare Shortcuts */
  132.     {
  133.         cp=shortcut;
  134.         while((cp=strchr(cp,'='))!=NULL)
  135.         {
  136.             if((*(cp-2) == dead) || (*(cp-3) == dead))
  137.                 return(dead);
  138.             cp++;
  139.         }
  140.     }
  141.  
  142.     for(i=0; i<sizeof(dk)/3; i++) /* erstes Zeichen der Liste abklappern */
  143.     {
  144.         if(dk[i].dead == dead)      /* Zeichen gefunden                          */
  145.             return(dead);
  146.     }
  147.     return(FALSE);
  148. }
  149. #endif
  150.  
  151. static void _loadshortcuts(char *filename)
  152. {
  153.     FILE *fp;
  154.     register char *cp;
  155.     
  156.     if((fp=fopen(filename,"rb"))!=NULL)    
  157.     {
  158.         form_write(menueditor,MENUTFILE,split_fname(filename),FALSE);
  159.         graf_mouse(BUSY_BEE,NULL);
  160.         if(shortcut)
  161.             free(shortcut);
  162.         if((shortcut=malloc(filelength(fileno(fp))+1))!=NULL)
  163.         {
  164.             fread(shortcut,1,filelength(fileno(fp)),fp);
  165.             shortcut[filelength(fileno(fp))]=0; /* letztes Zeichen eine 0 */
  166. /*
  167.             strcpy(filename,(char *)split_fname(filename));
  168.             if((cp=strchr(filename,'.'))!=NULL)
  169.                 *cp=0;
  170. */
  171.          strcpy(shortcutfile,(char *)split_fname(filename)); /* wird in Infozeile eingeblendet */
  172.  
  173.             if((cp=strrchr(shortcut,'#'))!=NULL) /* Kommentarkopf abschneiden */
  174.                 if((cp=strchr(cp,'\n'))!=NULL)
  175.                     memmove(shortcut,cp+1,strlen(cp+1)+1);
  176.             cp=shortcut;
  177.             while((cp=strchr(cp,'='))!=NULL)         /* Leerzeichen vor den '=' löschen */
  178.             {
  179.                 if(*(cp-1)==' ')
  180.                     memmove(cp-1,cp,strlen(cp)+1);
  181.                 else
  182.                     cp++;
  183.             }
  184.         }
  185.         else
  186.             form_alert(1,Adeadkey[0]);
  187.         fclose(fp);
  188.         graf_mouse(ARROW,NULL);
  189.     }
  190. }
  191.  
  192. void loadshortcuts(char *filename)
  193. {
  194.     FILE *fp;
  195.     char *cp,pathname[PATH_MAX];
  196.     
  197.     search_env(pathname,filename,FALSE); /* READ */
  198.     _loadshortcuts(pathname);
  199. }
  200.  
  201. static int _hndl_shortcuts(OBJECT *tree)
  202. {
  203.     FILE *fp;
  204.     char *cp,str[4],filename[PATH_MAX]="";
  205.     int a, exit_obj, last_entry=FALSE, desk=1, m_title, c_title, m_entry, c_entry;
  206.     /*static*/ char fpattern[FILENAME_MAX]="*.*";
  207.  
  208.     extern int boxw, windials;
  209.         
  210.     m_title=(winmenu+winmenu->ob_head)->ob_head;
  211.     c_title=(winmenu+m_title)->ob_head;
  212.     m_entry=(winmenu+winmenu->ob_tail)->ob_head;
  213.     c_entry=(winmenu+m_entry)->ob_head;
  214.  
  215.     tree[MENUTSAVE].ob_flags|=HIDETREE;
  216.  
  217.     tree[MENUMIDX].ob_flags&=~EDITABLE;
  218.     form_write(tree,MENUMNAME,(char *)winmenu[c_entry].ob_spec.index,FALSE);
  219.     sprintf(str,"%003d",c_entry);
  220.     
  221.     a = tree[MENUTAKTIV].ob_state; /* merken */
  222.     
  223.     form_write(tree,MENUMIDX,str,FALSE);
  224.     form_exopen(tree,0);
  225.    do
  226.    {
  227.       exit_obj=(form_exdo(tree,0)&0x7FFF);
  228.       switch(exit_obj)
  229.       {
  230.             case MENUMVOR:
  231.                 form_read(tree,MENUMNAME,(char *)winmenu[c_entry].ob_spec.index);
  232.                 c_entry=(winmenu+c_entry)->ob_next;
  233.                 if(desk) /* Deskmenu nicht auswerten */
  234.                 {
  235.                     c_entry=m_entry;
  236.                     desk=0;
  237.                 }
  238.                 if(c_entry == m_entry || c_entry == -1)
  239.                 {
  240.                     c_title=(winmenu+c_title)->ob_next;
  241.                     m_entry=(winmenu+m_entry)->ob_next;
  242.                     c_entry=(winmenu+m_entry)->ob_head;
  243.                     if(c_title==m_title)
  244.                     {
  245.                         m_title=(winmenu+winmenu->ob_head)->ob_head;
  246.                         c_title=(winmenu+m_title)->ob_head;
  247.                         m_entry=(winmenu+winmenu->ob_tail)->ob_head;
  248.                         c_entry=(winmenu+m_entry)->ob_head;
  249.                         desk=1;
  250.                     }
  251.                 }
  252.                 if(!*(char *)winmenu[c_entry].ob_spec.index ||
  253.                      *(char *)winmenu[c_entry].ob_spec.index == '-')
  254.                     c_entry=(winmenu+c_entry)->ob_next;
  255.                 while(c_entry>=WINDAT1 && c_entry<=WINDAT7) /* diese benötigen wir nicht */
  256.                     c_entry=(winmenu+c_entry)->ob_next;
  257.                 if(c_entry == m_entry || c_entry == -1)
  258.                 {  /* weiter zum nächsten Menü, wg. WINDAT7 = letzter Eintrag */
  259.                     c_title=(winmenu+c_title)->ob_next;
  260.                     m_entry=(winmenu+m_entry)->ob_next;
  261.                     c_entry=(winmenu+m_entry)->ob_head;
  262.                 }
  263.                 form_write(tree,MENUMNAME,(char *)winmenu[c_entry].ob_spec.index,TRUE);
  264.                 sprintf(str,"%003d",c_entry);
  265.                 form_write(tree,MENUMIDX,str,TRUE);
  266.                 evnt_timer(62,0);
  267.                 break;
  268.             case MENUMHELP:
  269.                form_alert(1,Adeadkey[4]);
  270.                 objc_change(tree,exit_obj,0,tree->ob_x,tree->ob_y,tree->ob_width,tree->ob_height,tree[exit_obj].ob_state&~SELECTED,TRUE);
  271.                 break;
  272.             case MENUMSAVE:
  273.                 form_read(tree,MENUMNAME,(char *)winmenu[c_entry].ob_spec.index);
  274.                 strcpy(fpattern,"*.MNU");
  275.                 find_7upinf(filename,"MNU",TRUE);
  276.                 if((cp=strrchr(filename,'\\'))!=NULL || (cp=strrchr(filename,'/'))!=NULL)
  277.                     strcpy(&cp[1],fpattern);
  278.                 else
  279.                     *filename=0;
  280.                 if(getfilename(filename,fpattern,"@",fselmsg[5]))
  281.                     _savemenu(filename);
  282.                 tree[exit_obj].ob_state&=~SELECTED;
  283.                 if(!windials)
  284.                     objc_update(tree,ROOT,MAX_DEPTH);
  285.                 else
  286.                     objc_update(tree,exit_obj,0);
  287.                break;
  288.             case MENUMLOAD:
  289.                /* muß TRUE, weil nicht 7UP.MNU sondern auch XYZ.MNU gültig ist */
  290.                 strcpy(fpattern,"*.MNU");
  291.                 find_7upinf(filename,"MNU",TRUE /*FALSE*/); 
  292.                 if((cp=strrchr(filename,'\\'))!=NULL || (cp=strrchr(filename,'/'))!=NULL)
  293.                     strcpy(&cp[1],fpattern);
  294.                 else
  295.                     *filename=0;
  296.                 if(getfilename(filename,fpattern,"@",fselmsg[6]))
  297.                 {
  298.                     _loadmenu(filename);
  299.                     form_write(tree,MENUMFILE,split_fname(filename),TRUE);
  300.                 }
  301.                 
  302.                 /* neu aufsetzen */
  303.                 m_title=(winmenu+winmenu->ob_head)->ob_head;
  304.                 c_title=(winmenu+m_title)->ob_head;
  305.                 m_entry=(winmenu+winmenu->ob_tail)->ob_head;
  306.                 c_entry=(winmenu+m_entry)->ob_head;
  307.  
  308.                 form_write(tree,MENUMNAME,(char *)winmenu[c_entry].ob_spec.index,TRUE);
  309.                 tree[exit_obj].ob_state&=~SELECTED;
  310.                 if(!windials)
  311.                     objc_update(tree,ROOT,MAX_DEPTH);
  312.                 else
  313.                     objc_update(tree,exit_obj,0);
  314.                break;
  315.             case MENUTHELP:
  316.                form_alert(1,Adeadkey[5]);
  317.                 objc_change(tree,exit_obj,0,tree->ob_x,tree->ob_y,tree->ob_width,tree->ob_height,tree[exit_obj].ob_state&~SELECTED,TRUE);
  318.                 break;
  319.             case MENUTSAVE:
  320.                 break;
  321.             case MENUTLOAD:
  322.                 strcpy(fpattern,"*.KBD");
  323.                 find_7upinf(filename,"KBD",TRUE /*FALSE*/);
  324.                 if((cp=strrchr(filename,'\\'))!=NULL || (cp=strrchr(filename,'/'))!=NULL)
  325.                     strcpy(&cp[1],fpattern);
  326.                 else
  327.                     *filename=0;
  328.                 if(getfilename(filename,fpattern,"@",fselmsg[7]))
  329.                 {
  330.                     _loadshortcuts(filename);
  331.                     form_write(tree,MENUTFILE,split_fname(filename),TRUE);
  332.                 }
  333.                 tree[exit_obj].ob_state&=~SELECTED;
  334.                 if(!windials)
  335.                     objc_update(tree,ROOT,MAX_DEPTH);
  336.                 else
  337.                     objc_update(tree,exit_obj,0);
  338.                break;
  339.             case MENUOK:
  340.                 form_read(tree,MENUMNAME,(char *)winmenu[c_entry].ob_spec.index);
  341.                 break;
  342.       }
  343.    }
  344.    while(exit_obj!=MENUOK);
  345.     form_exclose(tree,exit_obj,0);
  346.     if (exit_obj!=MENUOK)
  347.     {
  348.         tree[MENUTAKTIV].ob_state = a;
  349.     }
  350.     else
  351.     {
  352.         if(tree[MENUTAKTIV].ob_state & SELECTED)
  353.             scaktiv=TRUE;
  354.         else
  355.             scaktiv=FALSE;
  356.     }
  357. }
  358.  
  359. int hndl_shortcuts(void)
  360. {
  361.     int ret, kstate;
  362.  
  363.     graf_mkstate(&ret,&ret,&ret,&kstate);
  364.     if(kstate & (K_LSHIFT|K_RSHIFT))
  365.     {
  366.         if(shortcut)
  367.         {
  368.             free(shortcut);
  369.             shortcut=NULL;
  370.          *shortcutfile=0;
  371.             form_write(menueditor,MENUTFILE,"",FALSE);
  372.             return;
  373.         }
  374.     }
  375.    _hndl_shortcuts(menueditor);
  376. }
  377.